﻿//using System.Text;

//namespace WXWorkSvc.Common.TagHelpers;
///// <summary>
///// 字典的key必须是数字，除10的结果为行数 th表示文字 for表示属性
///// </summary>
//[HtmlTargetElement("table-head", Attributes = "asp-for-*")]
//[HtmlTargetElement("table-head", Attributes = "asp-th-*")]
//[HtmlTargetElement("table-head", TagStructure = TagStructure.WithoutEndTag)]
//public class TableHeaderTagHelper : TagHelper
//{
//    [HtmlAttributeName(DictionaryAttributePrefix = "asp-th-")]
//    public IDictionary<string, string> TableHeaders { get; set; } = new Dictionary<string, string>();
//    [HtmlAttributeName(DictionaryAttributePrefix = "asp-for-")]
//    public IDictionary<string, ModelExpression> Fors { get; set; } = new Dictionary<string, ModelExpression>();

//    public override void Process(TagHelperContext context, TagHelperOutput output)
//    {
//        output.TagMode = TagMode.StartTagAndEndTag;
//        var ths = new Dictionary<int, string>();

//        foreach (var item in Fors)
//            ths[int.Parse(item.Key)] = item.Value.GetDisplayName();
//        foreach (var item in TableHeaders)
//            ths[int.Parse(item.Key)] = item.Value;

//        var row = ths.Keys.Max() / 10;
//        StringBuilder sb = new StringBuilder();
//        for (int i = 0; i <= row; i++)
//        {
//            sb.Append("<tr>");
//            sb.AppendLine(string.Join("", ths.Where(ii => ii.Key / 10 == i).OrderBy(ii => ii.Key).Select(ii => $"<th>{ii.Value}</th>")));
//            sb.Append("</tr>");
//        }
//        output.Content.SetHtmlContent(sb.ToString());
//    }
//}
